
package com.phm.phmneuron.generator;

import com.phm.phmneuron.NeuralNetwork;
import java.util.List;
import java.util.Objects;

/**
 *
 * @author PARHAM
 */
public abstract class AutomatedDataGenerator{
    protected NeuralNetwork _network = null;
    protected DataGenerator _dgenerator = null;
    
    public AutomatedDataGenerator (NeuralNetwork net, DataGenerator dg) {
        setNeuralNetwork(net);
        setDataGenerator(dg);
    }
    
    public final void setDataGenerator (DataGenerator dg) {
        _dgenerator = Objects.requireNonNull(dg);
    }
    public final DataGenerator getDataGenerator () {
        return _dgenerator;
    }
    public final void setNeuralNetwork (NeuralNetwork net) {
        _network = Objects.requireNonNull(net);
    }
    public final NeuralNetwork getNeuralNetwork () {
        return _network;
    }
    
    public boolean train (int restrict) {
        if (_network == null ||
            _dgenerator.countRemainSignals() < restrict ||
            restrict < 0) return false;
        if (restrict == 0) {
            restrict = _dgenerator.countRemainSignals();
        }
        List<float []> buffer = _dgenerator.nextGeneratedSignals(restrict);
        return _network.learn(buffer);
    }
    public boolean train () {
        return train(0);
    }
} 
